import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import { systemid } from '../../atom/config';

interface Message {
	fitle: {
		equip_no: string
		companyname: string
		company_code: string
		plan_factory_name: string
		plan_factory_no: string
		maintain_factory_name: string
		stay_area: string
		security_level_ident: string
		principal_name: string
		principal_number: string
		planner_team_name: string
		planner_team_no: string
		planner_name: string
		planner_no: string
	};
}

export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	// todo
	const { insert, exec } = operate(action_id, session_id, systemid);
	insert('team_structure_attribute', {
		equip_no: msg.fitle.equip_no,
		companyname: msg.fitle.companyname,
		company_code: msg.fitle.company_code,
		plan_factory_name: msg.fitle.plan_factory_name,
		plan_factory_no: msg.fitle.plan_factory_no,
		maintain_factory_name: msg.fitle.maintain_factory_name,
		stay_area: msg.fitle.stay_area,
		security_level_ident: msg.fitle.security_level_ident,
		principal_name: msg.fitle.principal_name,
		principal_number: msg.fitle.principal_number,
		planner_team_name: msg.fitle.plan_factory_name,
		planner_team_no: msg.fitle.plan_factory_no,
		planner_name: msg.fitle.planner_name,
		planner_no: msg.fitle.planner_no
	});

	const rs = await exec();
	log(`Service end`);
	return rs;
}
